package drds.global_transaction.resource_manager.undolog.undolog_parser;

import com.google.gson.Gson;
import drds.common.Constants;
import drds.global_transaction.resource_manager.undolog.BranchUndoLog;
import lombok.extern.slf4j.Slf4j;

/**
 * fast json在对象解析方面存在问题,只能 gson
 */
@Slf4j
public class BasedOnJsonUndoLogParser implements UndoLogParser
{

	@Override
	public BranchUndoLog decode(String string)
	{
		Gson gson = new Gson();
		return gson.fromJson(string, BranchUndoLog.class);
	}

	@Override
	public String encode(BranchUndoLog branchUndoLog)
	{
		Gson gson = new Gson();
		String string = gson.toJson(branchUndoLog);
		if (Constants.developMode)
		{
			log.debug(BranchUndoLog.class.getSimpleName() + ":" + string);
		}
		return string;
	}
}
